import QtQuick
import QtQuick.Controls

Button {
    id:btn
    implicitWidth: 40
    implicitHeight: 40
    property color mouseenteredcolor : '#e4e4e4'
    property color mouseexitedcolor : '#ececec'
    property alias tiptext : tooltip.text
    property point firstHoverPos: Qt.point(0, 0)

    background: Rectangle {
        id:b
        color: mouseexitedcolor
        radius: 4
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onEntered: parent.color = mouseenteredcolor // 鼠标悬停时的颜色
            onExited: parent.color = mouseexitedcolor // 鼠标离开时的颜色
            onPositionChanged: (mouse)=>{
                if(!tooltip.visible){
                    firstHoverPos = Qt.point(mouse.x + 10, mouse.y + 10)
                }
            }
        }
    }
    ToolTip {
        id: tooltip
        x:firstHoverPos.x
        y:firstHoverPos.y
        visible: btn.hovered
        delay: 500
        contentItem: Text {
            text: tooltip.text
            color: '#575757'
        }
        background: Rectangle {
            color: '#ededed'
            border.width: 0
        }
    }
}
